<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class WeChatRule extends Model
{
    //
    protected $table = 'we_chat_rules';
    protected $fillable = ['site_id', 'module_id', 'module', 'wechat_id', 'type', 'title', 'options'];
    protected $casts =
        [
            'options' => 'array',
        ];

    public function keywords()
    {
        return $this->hasMany(WeChatKeyWord::class, 'rule_id');
    }

    public function text()
    {
        //将content通过数组形式，将一对多变成一对一
        return $this->hasOne(WeChatText::class, 'rule_id');
    }

    public function news()
    {
        return $this->hasOne(WeChatNews::class, 'rule_id');
    }
    public function wechat(){
        return $this->belongsTo(WeChat::class,'wechat_id');
    }
}
